--- title: "L1-046 整除光棍" created: 2025-11-28 tags: - 算法 --- # L1-046 整除光棍 ## 题目 [L1-046 整除光棍](https://pintia.cn/problem-sets/994805046380707840/exam/problems/type/7?problemSetProblemId=994805084284633088&page=0) ![[image-49149a71.png]] ## 思路分析 使用ull最多能到20位 有五个点过不去 使用高精度模拟 ## 代码实现 ull 15/20 ```cpp #include using namespace std; #define endl '\n' using ll = long long; using ull = unsigned long long; using PII = pair; using Pll = pair; int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1}; const int inf = 0x3f3f3f3f; const int N=25; ull nums[N]; int main() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); nums[1]=1; for(int i=2;i<=20;i++){ nums[i]=nums[i-1]*10+1; } // for(int i=1;i<=20;i++) cout<>x; for(int i=1;i<=20;i++){ if(nums[i]%x==0){ cout< using namespace std; #define endl '\n' using ll = long long; using ull = unsigned long long; using PII = pair; using Pll = pair; int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1}; const int inf = 0x3f3f3f3f; vector big_div(vector A,int b,int& r){ vector C; r=0; for(int i=A.size()-1;i>=0;i--){ r=r*10+A[i]; C.push_back(r/b); r%=b; } reverse(C.begin(),C.end()); while(C.size()>1 && C.back()==0) C.pop_back(); return C; } vector str2big(const string& s){ vector res; for(int i=s.size()-1;i>=0;i--){ if(isdigit(s[i])) res.push_back(s[i]-'0'); else if(s[i]=='-' && i==0) break; } while(res.size()>1 && res.back()==0) res.pop_back(); return res; } string big2str(const vector& A){ string res; for(int i=A.size()-1;i>=0;i--) res+=to_string(A[i]); return res.empty()?"0":res; } int main() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int x;cin>>x; string s="1"; vector A; while(true){ A=str2big(s); int r; vector ans=big_div(A,x,r); if(r==0){ cout<